public class Solution74 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int n=matrix.length,m=matrix[0].length;
        int i=n-1,j=0;
        while (i>=0 && i<n && j>=0 && j<m){
            if (target==matrix[i][j]){
                return true;
            }else if (matrix[i][j]<target){
                j++;
            }else{
                i--;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Solution74().searchMatrix(new int[][]{{1,3,5,7},{10,11,16,20},{23,30,34,60}},3));
    }
}
